package game.classes.gameField;

import game.classes.interfaces.Block;
import game.classes.interfaces.Movable;
import game.enums.BlockID;
import game.enums.MaterialID;

public class gameMovable extends gameUsable implements Movable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public gameMovable(int x, int y, BlockID id, Block[][] BlockList) {
		super(x, y, id, BlockList);
	}

	public gameMovable(int x, int y, BlockID bid, MaterialID mid, Block[][] BlockList) {
		super(x, y, bid, mid, BlockList);
	}

	@Override
	public boolean moveUp() {
		if (y > 0) {
			if (list[x][y-1].getBlockID() == BlockID.NONE) {
				gameBlock buff = (gameBlock) list[x][y-1];
				list[x][y-1] = this;
				list[x][y] = buff;
				y--;
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean moveLeft() {
		if (x > 0) {
			if (list[x-1][y].getBlockID() == BlockID.NONE) {
				gameBlock buff = (gameBlock) list[x-1][y];
				list[x-1][y] = this;
				list[x][y] = buff;
				x--;
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean moveRight() {
		if (x < list[0].length-1) {
			if (list[x+1][y].getBlockID() == BlockID.NONE) {
				gameBlock buff = (gameBlock) list[x+1][y];
				list[x+1][y] = this;
				list[x][y] = buff;
				x++;
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean moveDown() {
		if (y < list[0].length-1) {
			if (list[x][y+1].getBlockID() == BlockID.NONE) {
				gameBlock buff = (gameBlock) list[x][y+1];
				list[x][y+1] = this;
				list[x][y] = buff;
				y++;
				return true;
			}
		}
		return false;
	}

}
